﻿@{
    var companys = ViewData["Companys"] as List<Wicresoft.UnifyShow.Business.SiteBranchModel>;
    var isGlobalUser = (bool)ViewData["IsGlobalUser"];
    var myCompany = ViewData["CurrentCompany"] as Wicresoft.UnifyShow.Business.SiteBranchModel;
}
<form style="height: 220px;">
    <div id="searchParam" style="height: 90%;">
        <div>
            <div class="left">资产单位</div>
            <div class="right">
                <select data-source="Company">
                    @if (!isGlobalUser)
                    { 
                        <option value="@myCompany.Name">@myCompany.Name</option>
                    }
                    else
                    {
                        <option value="">全部</option>
                        foreach (var item in companys)
                        { 
                        <option value="@item.Name">@item.Name</option>
                        }
                    }
                </select>
            </div>
        </div>
        <div>
            <div class="left">硬件设备编号</div>
            <div class="right">
                <input type="text" data-source="Name" />
            </div>
        </div>
        <div>
            <div class="left">硬件设备名称</div>
            <div class="right">
                <input type="text" data-source="DeviceName" />
            </div>
        </div>
        <div>
            <div class="left">创建时间从</div>
            <div class="right">
                <input type="text" class="easyui-datebox" data-source="Create_Date_From" />
            </div>
        </div>
        <div>
            <div class="left">到</div>
            <div class="right">
                <input type="text" class="easyui-datebox" data-source="Create_Date_To" />
            </div>
        </div>
        <div>
            <div class="left">硬件设备序列号</div>
            <div class="right">
                <input type="text" data-source="SerialNumber" />
            </div>
        </div>
        <div>
            <div class="left">购置时间从</div>
            <div class="right">
                <input type="text" class="easyui-datebox" data-source="BuyTime_From" />
            </div>
        </div>
        <div>
            <div class="left">到</div>
            <div class="right">
                <input type="text" class="easyui-datebox" data-source="BuyTime_To" />
            </div>
        </div>
        <div>
            <div class="left">硬件分类</div>
            <div class="right">
                <select data-source="HDType">
                    <option value="">全部</option>
                    <option value="服务器">服务器</option>
                    <option value="存储">存储</option>
                    <option value="视频">视频</option>
                    <option value="机房">机房</option>
                    <option value="安全">安全</option>
                    <option value="网络">网络</option>
                    <option value="其他">其他</option>
                </select>
            </div>
        </div>
        <div>
            <div class="left">过保时间从</div>
            <div class="right">
                <input type="text" class="easyui-datebox" data-source="ExpireTime_From" />
            </div>
        </div>
        <div>
            <div class="left">到</div>
            <div class="right">
                <input type="text" class="easyui-datebox" data-source="ExpireTime_To" />
            </div>
        </div>
        <div>
            <div class="left">设备用途/业务系统</div>
            <div class="right">
                <input type="text" data-source="Usaged" />
            </div>
        </div>
        <div>
            <div class="left">报废时间从</div>
            <div class="right">
                <input type="text" class="easyui-datebox" data-source="DisposalDate_From" />
            </div>
        </div>
        <div>
            <div class="left">到</div>
            <div class="right">
                <input type="text" class="easyui-datebox" data-source="DisposalDate_To" />
            </div>
        </div>
        <div>
            <div class="left">资产IP地址</div>
            <div class="right">
                <input type="text" data-source="IPAddress" />
            </div>
        </div>
        <div>
            <div class="left">资产等级</div>
            <div class="right">
                <select data-source="VendorApplication">
                    <option value="">全部</option>
                    <option value="关键资产">关键资产</option>
                    <option value="重要资产">重要资产</option>
                    <option value="普通资产">普通资产</option>
                </select>
            </div>
        </div>
        <div>
            <div class="left">生产厂商</div>
            <div class="right">
                <input type="text" data-source="ManufacturerName" />
            </div>
        </div>
        <div>
            <div class="left">维保单位</div>
            <div class="right">
                <input type="text" />
            </div>
        </div>
        <div>
            <div class="left">物理位置</div>
            <div class="right">
                <input type="text" data-source="Room" />
            </div>
        </div>
        <div>
            <div class="left">责任部门</div>
            <div class="right">
                <input type="text" data-source="PrincipalDept" />
            </div>
        </div>
        <div>
            <div class="left">责任人</div>
            <div class="right">
                <input type="text" data-source="Principal" />
            </div>
        </div>
        <div class="one-line">
            <div class="left">
                <button type="button" onclick="groupHardwareList();">查询</button>
                <button type="reset">重置</button>
            </div>
            <div class="right"></div>
        </div>
    </div>
</form>
<div class="reportListContainer" style="top: 220px;">
    <div class="configButton">
        <button data-querytype="硬件综合" data-groupcode="" data-groupname="">报表配置</button>
        <iframe name="exportFrame" id="exportFrame" src="/ReportView/ExportReportViewToExcel" border="0" frameborder="0" style="border: none; height: 30px; vertical-align: middle; display: none;"></iframe>
    </div>
    <div class="reportList padding5">
        <div style="height: 30%;" id="searchGroupListContainer">
            <table id="searchGroupList"></table>
        </div>
        <div style="height: 65%; margin-top: 10px;" id="searchListContainer">
            <table id="searchList"></table>
        </div>
    </div>
</div>
<div class="bgWrapper">
    <div id="dimensionSetting">
        <div style="height: 30px; line-height: 30px;">
            汇总维度：
            <select id="groupList">
                <option value="HDType">硬件分类</option>
                <option value="IsExpired">是否过保</option>
            </select>
        </div>
        <div><span class="leftTip">所有列：</span><span class="rightTip">显示列：</span></div>
        <div class="multipleSelect">
            <select multiple="multiple" id="allSelectable">
            </select>
            <div class="operation">
                
                <div>
                    <button id="add">添加 ></button>
                </div>
                <div>
                    <button id="addAll">全部添加 >></button>
                </div>
                <div>
                    <button id="remove">&lt; 移除</button>
                </div>
                <div>
                    <button id="removeAll">&lt;&lt; 全部移除 </button>
                </div>
            </div>
            <select multiple="multiple" id="selected">
            </select>

        </div>
        <div style="margin: 10px 0;">
            <button class="update">确定</button>
            <button class="cancel">取消</button>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        $('.easyui-datebox').datebox({
            formatter: function (date) {
                return date.formate('yyyy-MM-dd')
            }
        });

        $('.bgWrapper .update').die('click').live('click', function () {
            var queryType = $('.configButton button').attr('data-querytype');
            updateSelectedColumns(queryType, function () {
                $('.bgWrapper').hide();
                groupHardwareList();
            });
        });
    });


    //分组统计硬件
    var groupHardwareList = function () {
        enableButton(false);
        $('#exportFrame').hide();

        var container = $('#searchParam');
        var query = ReportViewInsp.getQueryData(container);
        $.ajax({
            url: "/ReportView/GroupHardwareList",
            type: "POST",
            dataType: 'json',
            contentType: 'application/json',
            data: JSON.stringify({
                query: query
            }),
            success: function (res) {

                if (res && res.rows) {
                    var total = {};
                    total[res.groupCode] = '总计';
                    total['Count'] = res.total;
                    res.rows.push(total);

                    //设置维度值
                    $('[data-groupCode]').attr('data-groupCode', res.groupCode);
                    $('[data-groupName]').attr('data-groupName', res.groupName);

                    $('#searchGroupList').datagrid({
                        pagination: false,
                        fit: true,
                        fitColumns: true,
                        columns: [[
                            { field: 'ck', title: '全选', checkbox: true },
                            { field: res.groupCode, title: '汇总维度(' + res.groupName + ')', width: 120 },
                            { field: 'Count', title: '计数', width: 120 }
                        ]],
                        singleSelect: false,
                        data: res,
                        onLoadSuccess: function () {
                            $('#exportFrame').hide();
                            if ($('#searchGroupList').datagrid('getData').total > 0) {
                                $('#exportFrame').show();
                            }
                            enableButton(true);
                        
                        },
                        onCheck: function (index, row) {
                            searchHardwareList(ReportViewInsp.allQueryData(container, 'searchGroupList', res.groupCode));
                        },
                        onUncheck: function (index, row) {
                            searchHardwareList(ReportViewInsp.allQueryData(container, 'searchGroupList', res.groupCode));
                        },
                        onCheckAll: function (rows) {
                            searchHardwareList(ReportViewInsp.allQueryData(container, 'searchGroupList', res.groupCode));
                        },
                        onUncheckAll: function (rows) {
                            searchHardwareList(ReportViewInsp.allQueryData(container, 'searchGroupList', res.groupCode));
                        }
                    });

                    //$('#searchGroupListContainer').find('table tr.datagrid-row').first().click();
                }
            }
        });
    };

    var searchHardwareList = function (queryData) {
        var container = $('#searchParam');
        var query = queryData || ReportViewInsp.getQueryData(container);
        enableButton(false);
        $('#exportFrame').hide();
        $.ajax({
            url: '/ReportView/GetMySelectedColumns',
            data: {
                QueryType: "硬件综合"
            },
            success: function (res) {

                var selected = res.selectedColumns,
                    columns = [];

                $.each(selected, function (i, item) {
                    columns.push({ field: item.Field, title: item.Name, sortable: true, formatter: DateFormate });
                });

                $('#searchList').datagrid({
                    url: '/ReportView/SearchHardwareList',
                    pagination: true,
                    fit: true,
                    pageList: [10, 20],
                    pageSize: 20,
                    pageNumber: 1,
                    queryParams: query,
                    singleSelect: true,
                    sortName: 'Name',
                    sortOrder: 'desc',
                    columns: [columns],
                    onLoadSuccess: function () {
                        $('#exportFrame').hide();
                        if ($('#searchList').datagrid('getData').total > 0) {
                            $('#exportFrame').show();
                        }
                        enableButton(true);
                        
                    }
                });

                var p2 = $('#searchList').datagrid('getPager');
                $(p2).pagination({
                    beforePageText: '第',
                    afterPageText: '页&nbsp;共&nbsp;{pages}&nbsp;页',
                    displayMsg: '当前显示{from} - {to}&nbsp;条记录&nbsp;共&nbsp;{total}&nbsp;条记录'

                });
            }
        })


    };
</script>
